package com.wjw.effectivejava1;

import java.math.BigInteger;

public class Complex {

    private final double re;
    private final double im;

    public Complex(double re, double im){
        this.re = re;
        this.im = im;
    }

    public double realPart() {return re;}
    public double imaginaryPart() {return im;}

    public Complex plus(Complex c){
        return new Complex(re + c.re, im + c.im);
    }

    public Complex minus(Complex c){
        return new Complex(re - c.re, im - c.im);
    }

    public static Complex valueOf(double re, double im){
        return new Complex(re, im);
    }

    public static BigInteger safeInstance(BigInteger val){
        return val.getClass() == BigInteger.class ? val : new BigInteger(val.toByteArray());
    }
}
